home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
include
/
ringbuf.h
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-08
|
2KB
|
57 lines
/*
| file - ringbuf.h
|===================================================================
|
| copyright (C) 1987, V.I. Corporation
|
| ringbuf.h -- ringbuffer typedefs and macros
|
| Alan C Morse 11 Dec 87
|
|===================================================================
|
| include-file description/function:
| Typedefs and macros for creating and accessing ring buffer
| structures.
| NOTE that all indices into the buffer must be positive.
|
|===================================================================
*/
typedef struct
{
short NumEntries; /* Number of entries in the ring buffer */
short EntrySize; /* Size in bytes of an entry in the buffer */
short NowIndex; /* Current position in the buffer */
char *buffer;
} RING_BUFFER;
#define CREATE_RING_BUFFER( rb, n, s ) \
{ \
rb = (RING_BUFFER*)S_ALLOC( sizeof(RING_BUFFER) ); \
((RING_BUFFER*)rb)->NumEntries = n; \
((RING_BUFFER*)rb)->EntrySize = s; \
((RING_BUFFER*)rb)->NowIndex = 0; \
((RING_BUFFER*)rb)->buffer = S_ALLOC( n * s ); \
memset(((RING_BUFFER*)rb)->buffer,0,(n*s));\
}
#define DESTROY_RING_BUFFER( rb ) \
{ \
S_FREE( (ADDRESS)((RING_BUFFER*)rb)->buffer ); \
S_FREE( (ADDRESS)((RING_BUFFER*)rb) ); \
}
/* Moves the current position of the ring buffer i positions */
#define INCREMENT_RING_BUFFER( rb, i ) \
((RING_BUFFER*)rb)->NowIndex = \
( ((RING_BUFFER*)rb)->NowIndex + (i) ) % \
((RING_BUFFER*)rb)->NumEntries; \
/* Returns the address of the i-th entry in the ring buffer */
#define RING_BUFFER_ENTRY( rb, i ) \
( ( ( (((RING_BUFFER*)rb)->NowIndex + (i)) % \
((RING_BUFFER*)rb)->NumEntries ) * \
((RING_BUFFER*)rb)->EntrySize ) + \
((RING_BUFFER*)rb)->buffer ) \